﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using snat.model;

namespace snat.algorithms.network.TFIDF {
    public class TwitterDocument : Document {

        Regex re = new Regex("[ ,.]+");

        public TwitterDocument(Message m, ref Dictionary<String, Term> terms, bool updateTerms)
            : base(m, ref terms, updateTerms) {
            String[] words = re.Split(m.Data);
            if (words.Length == 0) { return; }

            foreach (String word in words) {
                if (!terms.ContainsKey(word) && updateTerms) {
                    terms.Add(word, new Term(word));
                }
                terms[word].AppearenceCount++;
                if (!tf.ContainsKey(terms[word])) {
                    tf.Add(terms[word], 1);
                } else {
                    tf[terms[word]]++;
                }
            }
            tf.Values.ToList().ForEach(e => e /= words.Length);
        }

        public override String DocumentType {
            get {
                return base.DocumentType + "Twitter";
            }
        }

    }
}
